# coding: utf-8
from __future__ import print_function
import os, yaml


'''
加载yaml配置文件
'''
current_path = os.path.split(os.path.realpath(__file__))[0]
f = open(os.path.join(current_path, 'alg_config.yaml'), 'r', encoding='utf-8')
result = f.read()
config_data = yaml.load(result, Loader=yaml.FullLoader)
parent_path = os.path.dirname(current_path)
ROOT_PATH = config_data["ROOT_PATH"]


class Config:
    def __init__(self):
        # 1) 印刷缺陷参数
        self.IS_GEN_ONLINE = config_data["GEN_PRINTING_DEFECT"]["IS_GEN_ONLINE"]
        self.IS_GEN_BACKGROUND = config_data["GEN_PRINTING_DEFECT"]["IS_GEN_BACKGROUND"]
        self.INPUT_ORIGINAL_DATA_ROOT = os.path.join(ROOT_PATH, config_data["GEN_PRINTING_DEFECT"]["INPUT_ORIGINAL_DATA_ROOT"].strip('/'))
        self.OUTPUT_GEN_DEFECT_ROOT = os.path.join(ROOT_PATH, config_data["GEN_PRINTING_DEFECT"]["OUTPUT_GEN_DEFECT_ROOT"].strip('/'))
        self.DEFECT_MASK_ROOT = os.path.join(ROOT_PATH, config_data["GEN_PRINTING_DEFECT"]["DEFECT_MASK_ROOT"].strip('/'))
        self.SAMPLE_NUM = config_data["GEN_PRINTING_DEFECT"]["SAMPLE_NUM"]
        self.DEFECT_SPECIAL_NAME = config_data["GEN_PRINTING_DEFECT"]["DEFECT_SPECIAL_NAME"]
        self.PRINTING_DEFECT_NAME_DICT = config_data["GEN_PRINTING_DEFECT"]["PRINTING_DEFECT_NAME_DICT"]
        self.PRINTING_DEFECT_NAME_LIST = list(self.PRINTING_DEFECT_NAME_DICT.keys())

        # Data converter
        self.LOAD_LABELME_JSON_PATH = os.path.join(ROOT_PATH, config_data["CONVERTER"]["LOAD_LABELME_JSON_PATH"].strip('/'))
        self.SAVE_YOLO_TXT_PATH = os.path.join(ROOT_PATH, config_data["CONVERTER"]["SAVE_YOLO_TXT_PATH"].strip('/'))
        self.YOLO_TASK_TYPE = config_data["CONVERTER"]["YOLO_TASK_TYPE"]